home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / swingall.jar / javax / swing / text / rtf / RTFGenerator.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-07-15  |  14.5 KB  |  783 lines

  1. package javax.swing.text.rtf;
  2.  
  3. import java.awt.Color;
  4. import java.io.IOException;
  5. import java.io.OutputStream;
  6. import java.util.Dictionary;
  7. import java.util.Enumeration;
  8. import java.util.Hashtable;
  9. import java.util.Vector;
  10. import javax.swing.text.AttributeSet;
  11. import javax.swing.text.BadLocationException;
  12. import javax.swing.text.Document;
  13. import javax.swing.text.Element;
  14. import javax.swing.text.MutableAttributeSet;
  15. import javax.swing.text.Segment;
  16. import javax.swing.text.SimpleAttributeSet;
  17. import javax.swing.text.Style;
  18. import javax.swing.text.StyleConstants;
  19. import javax.swing.text.TabStop;
  20.  
  21. class RTFGenerator {
  22.    Dictionary colorTable = new Hashtable();
  23.    int colorCount;
  24.    Dictionary fontTable;
  25.    int fontCount;
  26.    Dictionary styleTable;
  27.    int styleCount;
  28.    OutputStream outputStream;
  29.    boolean afterKeyword;
  30.    MutableAttributeSet outputAttributes;
  31.    int unicodeCount;
  32.    private Segment workingSegment;
  33.    int[] outputConversion;
  34.    public static final Color defaultRTFColor;
  35.    public static final float defaultFontSize = 12.0F;
  36.    public static final String defaultFontFamily = "Helvetica";
  37.    protected static Integer One;
  38.    protected static Integer Zero;
  39.    protected static Boolean False;
  40.    protected static Float ZeroPointZero;
  41.    private static Object MagicToken;
  42.    protected static CharacterKeywordPair[] textKeywords;
  43.    static final char[] hexdigits;
  44.  
  45.    static {
  46.       defaultRTFColor = Color.black;
  47.       One = new Integer(1);
  48.       Zero = new Integer(0);
  49.       False = new Boolean(false);
  50.       MagicToken = new Object();
  51.       ZeroPointZero = new Float(0.0F);
  52.       Dictionary var0 = RTFReader.textKeywords;
  53.       Enumeration var1 = var0.keys();
  54.       Vector var2 = new Vector();
  55.  
  56.       while(var1.hasMoreElements()) {
  57.          CharacterKeywordPair var3 = new CharacterKeywordPair();
  58.          var3.keyword = (String)var1.nextElement();
  59.          var3.character = ((String)var0.get(var3.keyword)).charAt(0);
  60.          var2.addElement(var3);
  61.       }
  62.  
  63.       textKeywords = new CharacterKeywordPair[var2.size()];
  64.       var2.copyInto(textKeywords);
  65.       hexdigits = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
  66.    }
  67.  
  68.    public RTFGenerator(OutputStream var1) {
  69.       this.colorTable.put(defaultRTFColor, new Integer(0));
  70.       this.colorCount = 1;
  71.       this.fontTable = new Hashtable();
  72.       this.fontCount = 0;
  73.       this.styleTable = new Hashtable();
  74.       this.styleCount = 0;
  75.       this.workingSegment = new Segment();
  76.       this.outputStream = var1;
  77.       this.unicodeCount = 1;
  78.    }
  79.  
  80.    String approximationForUnicode(char var1) {
  81.       return "?";
  82.    }
  83.  
  84.    private static Object attrDiff(MutableAttributeSet var0, AttributeSet var1, Object var2, Object var3) {
  85.       Object var4 = var0.getAttribute(var2);
  86.       Object var5 = var1.getAttribute(var2);
  87.       if (var5 == var4) {
  88.          return null;
  89.       } else if (var5 == null) {
  90.          var0.removeAttribute(var2);
  91.          return var3 != null && !var3.equals(var4) ? var3 : null;
  92.       } else if (var4 != null && equalArraysOK(var4, var5)) {
  93.          return null;
  94.       } else {
  95.          var0.addAttribute(var2, var5);
  96.          return var5;
  97.       }
  98.    }
  99.  
  100.    protected void checkControlWord(MutableAttributeSet var1, AttributeSet var2, RTFAttribute var3) throws IOException {
  101.       Object var4;
  102.       if ((var4 = attrDiff(var1, var2, var3.swingName(), MagicToken)) != null) {
  103.          if (var4 == MagicToken) {
  104.             var4 = null;
  105.          }
  106.  
  107.          var3.writeValue(var4, this, true);
  108.       }
  109.  
  110.    }
  111.  
  112.    protected void checkControlWords(MutableAttributeSet var1, AttributeSet var2, RTFAttribute[] var3, int var4) throws IOException {
  113.       for(RTFAttribute var7 : var3) {
  114.          if (var7.domain() == var4) {
  115.             this.checkControlWord(var1, var2, var7);
  116.          }
  117.       }
  118.  
  119.    }
  120.  
  121.    protected void checkNumericControlWord(MutableAttributeSet var1, AttributeSet var2, Object var3, String var4, float var5, float var6) throws IOException {
  122.       Object var7;
  123.       if ((var7 = attrDiff(var1, var2, var3, MagicToken)) != null) {
  124.          float var8;
  125.          if (var7 == MagicToken) {
  126.             var8 = var5;
  127.          } else {
  128.             var8 = ((Number)var7).floatValue();
  129.          }
  130.  
  131.          this.writeControlWord(var4, Math.round(var8 * var6));
  132.       }
  133.  
  134.    }
  135.  
  136.    protected static int convertCharacter(int[] var0, char var1) {
  137.       for(int var2 = 0; var2 < var0.length; var2 += 2) {
  138.          if (var0[var2] == var1) {
  139.             return var0[var2 + 1];
  140.          }
  141.       }
  142.  
  143.       return 0;
  144.    }
  145.  
  146.    private static boolean equalArraysOK(Object var0, Object var1) {
  147.       if (var0 == var1) {
  148.          return true;
  149.       } else if (var0 != null && var1 != null) {
  150.          if (var0.equals(var1)) {
  151.             return true;
  152.          } else if (var0.getClass().isArray() && var1.getClass().isArray()) {
  153.             Object[] var2 = var0;
  154.             Object[] var3 = var1;
  155.             if (var2.length != var3.length) {
  156.                return false;
  157.             } else {
  158.                int var5 = var2.length;
  159.  
  160.                for(int var4 = 0; var4 < var5; ++var4) {
  161.                   if (!equalArraysOK(var2[var4], var3[var4])) {
  162.                      return false;
  163.                   }
  164.                }
  165.  
  166.                return true;
  167.             }
  168.          } else {
  169.             return false;
  170.          }
  171.       } else {
  172.          return false;
  173.       }
  174.    }
  175.  
  176.    public void examineElement(Element var1) {
  177.       AttributeSet var2 = var1.getAttributes();
  178.       this.tallyStyles(var2);
  179.       if (var2 != null) {
  180.          Color var4 = StyleConstants.getForeground(var2);
  181.          if (var4 != null && this.colorTable.get(var4) == null) {
  182.             this.colorTable.put(var4, new Integer(this.colorCount));
  183.             ++this.colorCount;
  184.          }
  185.  
  186.          Object var5 = var2.getAttribute(StyleConstants.Background);
  187.          if (var5 != null && this.colorTable.get(var5) == null) {
  188.             this.colorTable.put(var5, new Integer(this.colorCount));
  189.             ++this.colorCount;
  190.          }
  191.  
  192.          String var3 = StyleConstants.getFontFamily(var2);
  193.          if (var3 == null) {
  194.             var3 = "Helvetica";
  195.          }
  196.  
  197.          if (var3 != null && this.fontTable.get(var3) == null) {
  198.             this.fontTable.put(var3, new Integer(this.fontCount));
  199.             ++this.fontCount;
  200.          }
  201.       }
  202.  
  203.       int var6 = var1.getElementCount();
  204.  
  205.       for(int var7 = 0; var7 < var6; ++var7) {
  206.          this.examineElement(var1.getElement(var7));
  207.       }
  208.  
  209.    }
  210.  
  211.    private Style findStyle(AttributeSet var1) {
  212.       for(; var1 != null; var1 = var1.getResolveParent()) {
  213.          if (var1 instanceof Style) {
  214.             Object var2 = this.styleTable.get(var1);
  215.             if (var2 != null) {
  216.                return (Style)var1;
  217.             }
  218.          }
  219.       }
  220.  
  221.       return null;
  222.    }
  223.  
  224.    private Integer findStyleNumber(AttributeSet var1, String var2) {
  225.       for(; var1 != null; var1 = var1.getResolveParent()) {
  226.          if (var1 instanceof Style) {
  227.             Integer var3 = (Integer)this.styleTable.get(var1);
  228.             if (var3 != null && (var2 == null || var2.equals(var1.getAttribute("style:type")))) {
  229.                return var3;
  230.             }
  231.          }
  232.       }
  233.  
  234.       return null;
  235.    }
  236.  
  237.    static int[] outputConversionForName(String var0) throws IOException {
  238.       char[] var1 = (char[])RTFReader.getCharacterSet(var0);
  239.       return outputConversionFromTranslationTable(var1);
  240.    }
  241.  
  242.    static int[] outputConversionFromTranslationTable(char[] var0) {
  243.       int[] var1 = new int[2 * var0.length];
  244.  
  245.       for(int var2 = 0; var2 < var0.length; var1[var2 * 2 + 1] = var2++) {
  246.          var1[var2 * 2] = var0[var2];
  247.       }
  248.  
  249.       return var1;
  250.    }
  251.  
  252.    protected void resetCharacterAttributes(MutableAttributeSet var1) throws IOException {
  253.       this.writeControlWord("plain");
  254.       int var3 = RTFAttributes.attributes.length;
  255.  
  256.       for(int var2 = 0; var2 < var3; ++var2) {
  257.          RTFAttribute var4 = RTFAttributes.attributes[var2];
  258.          if (var4.domain() == 0) {
  259.             var4.setDefault(var1);
  260.          }
  261.       }
  262.  
  263.       StyleConstants.setFontFamily(var1, "Helvetica");
  264.       var1.removeAttribute(StyleConstants.FontSize);
  265.       var1.removeAttribute(StyleConstants.Background);
  266.       var1.removeAttribute(StyleConstants.Foreground);
  267.       var1.removeAttribute(StyleConstants.LineSpacing);
  268.       var1.removeAttribute("characterStyle");
  269.    }
  270.  
  271.    protected void resetParagraphAttributes(MutableAttributeSet var1) throws IOException {
  272.       this.writeControlWord("pard");
  273.       var1.addAttribute(StyleConstants.Alignment, Zero);
  274.       int var3 = RTFAttributes.attributes.length;
  275.  
  276.       for(int var2 = 0; var2 < var3; ++var2) {
  277.          RTFAttribute var4 = RTFAttributes.attributes[var2];
  278.          if (var4.domain() == 1) {
  279.             var4.setDefault(var1);
  280.          }
  281.       }
  282.  
  283.       var1.removeAttribute("paragraphStyle");
  284.       var1.removeAttribute("tabs");
  285.    }
  286.  
  287.    protected void resetSectionAttributes(MutableAttributeSet var1) throws IOException {
  288.       this.writeControlWord("sectd");
  289.       int var3 = RTFAttributes.attributes.length;
  290.  
  291.       for(int var2 = 0; var2 < var3; ++var2) {
  292.          RTFAttribute var4 = RTFAttributes.attributes[var2];
  293.          if (var4.domain() == 2) {
  294.             var4.setDefault(var1);
  295.          }
  296.       }
  297.  
  298.       var1.removeAttribute("sectionStyle");
  299.    }
  300.  
  301.    private void tallyStyles(AttributeSet var1) {
  302.       for(; var1 != null; var1 = var1.getResolveParent()) {
  303.          if (var1 instanceof Style) {
  304.             Integer var2 = (Integer)this.styleTable.get(var1);
  305.             if (var2 == null) {
  306.                ++this.styleCount;
  307.                var2 = new Integer(this.styleCount);
  308.                this.styleTable.put(var1, var2);
  309.             }
  310.          }
  311.       }
  312.  
  313.    }
  314.  
  315.    void updateCharacterAttributes(MutableAttributeSet var1, AttributeSet var2, boolean var3) throws IOException {
  316.       if (var3) {
  317.          Object var5 = var1.getAttribute("characterStyle");
  318.          Integer var6 = this.findStyleNumber(var2, "character");
  319.          if (var5 != var6) {
  320.             if (var5 != null) {
  321.                this.resetCharacterAttributes(var1);
  322.             }
  323.  
  324.             if (var6 != null) {
  325.                this.writeControlWord("cs", (Integer)var6);
  326.                var1.addAttribute("characterStyle", var6);
  327.             } else {
  328.                var1.removeAttribute("characterStyle");
  329.             }
  330.          }
  331.       }
  332.  
  333.       Object var4;
  334.       if ((var4 = attrDiff(var1, var2, StyleConstants.FontFamily, (Object)null)) != null) {
  335.          Number var9 = (Number)this.fontTable.get(var4);
  336.          this.writeControlWord("f", var9.intValue());
  337.       }
  338.  
  339.       this.checkNumericControlWord(var1, var2, StyleConstants.FontSize, "fs", 12.0F, 2.0F);
  340.       this.checkControlWords(var1, var2, RTFAttributes.attributes, 0);
  341.       this.checkNumericControlWord(var1, var2, StyleConstants.LineSpacing, "sl", 0.0F, 20.0F);
  342.       if ((var4 = attrDiff(var1, var2, StyleConstants.Background, MagicToken)) != null) {
  343.          int var10;
  344.          if (var4 == MagicToken) {
  345.             var10 = 0;
  346.          } else {
  347.             var10 = ((Number)this.colorTable.get(var4)).intValue();
  348.          }
  349.  
  350.          this.writeControlWord("cb", var10);
  351.       }
  352.  
  353.       if ((var4 = attrDiff(var1, var2, StyleConstants.Foreground, (Object)null)) != null) {
  354.          int var11;
  355.          if (var4 == MagicToken) {
  356.             var11 = 0;
  357.          } else {
  358.             var11 = ((Number)this.colorTable.get(var4)).intValue();
  359.          }
  360.  
  361.          this.writeControlWord("cf", var11);
  362.       }
  363.  
  364.    }
  365.  
  366.    void updateParagraphAttributes(MutableAttributeSet var1, AttributeSet var2, boolean var3) throws IOException {
  367.       Object var5;
  368.       Integer var6;
  369.       if (var3) {
  370.          var5 = var1.getAttribute("paragraphStyle");
  371.          var6 = this.findStyleNumber(var2, "paragraph");
  372.          if (var5 != var6 && var5 != null) {
  373.             this.resetParagraphAttributes(var1);
  374.             var5 = null;
  375.          }
  376.       } else {
  377.          var5 = null;
  378.          var6 = null;
  379.       }
  380.  
  381.       Object var7 = var1.getAttribute("tabs");
  382.       Object var8 = var2.getAttribute("tabs");
  383.       if (var7 != var8 && var7 != null) {
  384.          this.resetParagraphAttributes(var1);
  385.          var7 = null;
  386.          var5 = null;
  387.       }
  388.  
  389.       if (var5 != var6 && var6 != null) {
  390.          this.writeControlWord("s", (Integer)var6);
  391.          var1.addAttribute("paragraphStyle", var6);
  392.       }
  393.  
  394.       this.checkControlWords(var1, var2, RTFAttributes.attributes, 1);
  395.       if (var7 != var8 && var8 != null) {
  396.          TabStop[] var9 = (TabStop[])var8;
  397.  
  398.          for(int var10 = 0; var10 < var9.length; ++var10) {
  399.             TabStop var11 = var9[var10];
  400.             switch (var11.getAlignment()) {
  401.                case 0:
  402.                case 3:
  403.                case 5:
  404.                default:
  405.                   break;
  406.                case 1:
  407.                   this.writeControlWord("tqr");
  408.                   break;
  409.                case 2:
  410.                   this.writeControlWord("tqc");
  411.                   break;
  412.                case 4:
  413.                   this.writeControlWord("tqdec");
  414.             }
  415.  
  416.             switch (var11.getLeader()) {
  417.                case 0:
  418.                default:
  419.                   break;
  420.                case 1:
  421.                   this.writeControlWord("tldot");
  422.                   break;
  423.                case 2:
  424.                   this.writeControlWord("tlhyph");
  425.                   break;
  426.                case 3:
  427.                   this.writeControlWord("tlul");
  428.                   break;
  429.                case 4:
  430.                   this.writeControlWord("tlth");
  431.                   break;
  432.                case 5:
  433.                   this.writeControlWord("tleq");
  434.             }
  435.  
  436.             int var12 = Math.round(20.0F * var11.getPosition());
  437.             if (var11.getAlignment() == 5) {
  438.                this.writeControlWord("tb", var12);
  439.             } else {
  440.                this.writeControlWord("tx", var12);
  441.             }
  442.          }
  443.  
  444.          var1.addAttribute("tabs", var9);
  445.       }
  446.  
  447.    }
  448.  
  449.    void updateSectionAttributes(MutableAttributeSet var1, AttributeSet var2, boolean var3) throws IOException {
  450.       if (var3) {
  451.          Object var4 = var1.getAttribute("sectionStyle");
  452.          Integer var5 = this.findStyleNumber(var2, "section");
  453.          if (var4 != var5) {
  454.             if (var4 != null) {
  455.                this.resetSectionAttributes(var1);
  456.             }
  457.  
  458.             if (var5 != null) {
  459.                this.writeControlWord("ds", (Integer)var5);
  460.                var1.addAttribute("sectionStyle", var5);
  461.             } else {
  462.                var1.removeAttribute("sectionStyle");
  463.             }
  464.          }
  465.       }
  466.  
  467.       this.checkControlWords(var1, var2, RTFAttributes.attributes, 2);
  468.    }
  469.  
  470.    public void writeBegingroup() throws IOException {
  471.       this.outputStream.write(123);
  472.       this.afterKeyword = false;
  473.    }
  474.  
  475.    public void writeCharacter(char var1) throws IOException {
  476.       if (var1 == 160) {
  477.          this.outputStream.write(92);
  478.          this.outputStream.write(126);
  479.          this.afterKeyword = false;
  480.       } else if (var1 == '\t') {
  481.          this.writeControlWord("tab");
  482.       } else if (var1 != '\n' && var1 != '\r') {
  483.          int var2 = convertCharacter(this.outputConversion, var1);
  484.          if (var2 != 0) {
  485.             if (var2 > 127) {
  486.                this.outputStream.write(92);
  487.                this.outputStream.write(39);
  488.                int var5 = (var2 & 240) >>> 4;
  489.                this.outputStream.write(hexdigits[var5]);
  490.                var5 = var2 & 15;
  491.                this.outputStream.write(hexdigits[var5]);
  492.                this.afterKeyword = false;
  493.             } else {
  494.                switch (var2) {
  495.                   case 92:
  496.                   case 123:
  497.                   case 125:
  498.                      this.outputStream.write(92);
  499.                      this.afterKeyword = false;
  500.                   default:
  501.                      if (this.afterKeyword) {
  502.                         this.outputStream.write(32);
  503.                         this.afterKeyword = false;
  504.                      }
  505.  
  506.                      this.outputStream.write(var2);
  507.                }
  508.             }
  509.          } else {
  510.             for(int var3 = 0; var3 < textKeywords.length; ++var3) {
  511.                if (textKeywords[var3].character == var1) {
  512.                   this.writeControlWord(textKeywords[var3].keyword);
  513.                   return;
  514.                }
  515.             }
  516.  
  517.             String var4 = this.approximationForUnicode(var1);
  518.             if (var4.length() != this.unicodeCount) {
  519.                this.unicodeCount = var4.length();
  520.                this.writeControlWord("uc", this.unicodeCount);
  521.             }
  522.  
  523.             this.writeControlWord("u", var1);
  524.             this.writeRawString(" ");
  525.             this.writeRawString(var4);
  526.             this.afterKeyword = false;
  527.          }
  528.       }
  529.    }
  530.  
  531.    public void writeControlWord(String var1) throws IOException {
  532.       this.outputStream.write(92);
  533.       this.writeRawString(var1);
  534.       this.afterKeyword = true;
  535.    }
  536.  
  537.    public void writeControlWord(String var1, int var2) throws IOException {
  538.       this.outputStream.write(92);
  539.       this.writeRawString(var1);
  540.       this.writeRawString(String.valueOf(var2));
  541.       this.afterKeyword = true;
  542.    }
  543.  
  544.    public static void writeDocument(Document var0, OutputStream var1) throws IOException {
  545.       RTFGenerator var2 = new RTFGenerator(var1);
  546.       Element var3 = var0.getDefaultRootElement();
  547.       var2.examineElement(var3);
  548.       var2.writeRTFHeader();
  549.       var2.writeDocumentProperties(var0);
  550.       int var4 = var3.getElementCount();
  551.  
  552.       for(int var5 = 0; var5 < var4; ++var5) {
  553.          var2.writeParagraphElement(var3.getElement(var5));
  554.       }
  555.  
  556.       var2.writeRTFTrailer();
  557.    }
  558.  
  559.    void writeDocumentProperties(Document var1) throws IOException {
  560.       boolean var3 = false;
  561.  
  562.       for(int var2 = 0; var2 < RTFAttributes.attributes.length; ++var2) {
  563.          RTFAttribute var4 = RTFAttributes.attributes[var2];
  564.          if (var4.domain() == 3) {
  565.             Object var5 = var1.getProperty(var4.swingName());
  566.             boolean var6 = var4.writeValue(var5, this, false);
  567.             if (var6) {
  568.                var3 = true;
  569.             }
  570.          }
  571.       }
  572.  
  573.       if (var3) {
  574.          this.writeLineBreak();
  575.       }
  576.  
  577.    }
  578.  
  579.    public void writeEndgroup() throws IOException {
  580.       this.outputStream.write(125);
  581.       this.afterKeyword = false;
  582.    }
  583.  
  584.    public void writeLineBreak() throws IOException {
  585.       this.writeRawString("\n");
  586.       this.afterKeyword = false;
  587.    }
  588.  
  589.    public void writeParagraphElement(Element var1) throws IOException {
  590.       this.updateParagraphAttributes(this.outputAttributes, var1.getAttributes(), true);
  591.       int var2 = var1.getElementCount();
  592.  
  593.       for(int var3 = 0; var3 < var2; ++var3) {
  594.          this.writeTextElement(var1.getElement(var3));
  595.       }
  596.  
  597.       this.writeControlWord("par");
  598.       this.writeLineBreak();
  599.    }
  600.  
  601.    public void writeRTFHeader() throws IOException {
  602.       this.writeBegingroup();
  603.       this.writeControlWord("rtf", 1);
  604.       this.writeControlWord("ansi");
  605.       this.outputConversion = outputConversionForName("ansi");
  606.       this.writeLineBreak();
  607.       String[] var2 = new String[this.fontCount];
  608.  
  609.       String var4;
  610.       Integer var5;
  611.       for(Enumeration var3 = this.fontTable.keys(); var3.hasMoreElements(); var2[var5] = var4) {
  612.          var4 = (String)var3.nextElement();
  613.          var5 = (Integer)this.fontTable.get(var4);
  614.       }
  615.  
  616.       this.writeBegingroup();
  617.       this.writeControlWord("fonttbl");
  618.  
  619.       for(int var1 = 0; var1 < this.fontCount; ++var1) {
  620.          this.writeControlWord("f", var1);
  621.          this.writeControlWord("fnil");
  622.          this.writeText(var2[var1]);
  623.          this.writeText(";");
  624.       }
  625.  
  626.       this.writeEndgroup();
  627.       this.writeLineBreak();
  628.       if (this.colorCount > 1) {
  629.          Color[] var15 = new Color[this.colorCount];
  630.  
  631.          Color var7;
  632.          Integer var8;
  633.          for(Enumeration var6 = this.colorTable.keys(); var6.hasMoreElements(); var15[var8] = var7) {
  634.             var7 = (Color)var6.nextElement();
  635.             var8 = (Integer)this.colorTable.get(var7);
  636.          }
  637.  
  638.          this.writeBegingroup();
  639.          this.writeControlWord("colortbl");
  640.  
  641.          for(int var14 = 0; var14 < this.colorCount; ++var14) {
  642.             var7 = var15[var14];
  643.             if (var7 != null) {
  644.                this.writeControlWord("red", var7.getRed());
  645.                this.writeControlWord("green", var7.getGreen());
  646.                this.writeControlWord("blue", var7.getBlue());
  647.             }
  648.  
  649.             this.writeRawString(";");
  650.          }
  651.  
  652.          this.writeEndgroup();
  653.          this.writeLineBreak();
  654.       }
  655.  
  656.       if (this.styleCount > 1) {
  657.          this.writeBegingroup();
  658.          this.writeControlWord("stylesheet");
  659.          Enumeration var16 = this.styleTable.keys();
  660.  
  661.          while(var16.hasMoreElements()) {
  662.             Style var17 = (Style)var16.nextElement();
  663.             int var19 = (Integer)this.styleTable.get(var17);
  664.             this.writeBegingroup();
  665.             String var20 = (String)var17.getAttribute("style:type");
  666.             if (var20 == null) {
  667.                var20 = "paragraph";
  668.             }
  669.  
  670.             if (var20.equals("character")) {
  671.                this.writeControlWord("*");
  672.                this.writeControlWord("cs", var19);
  673.             } else if (var20.equals("section")) {
  674.                this.writeControlWord("*");
  675.                this.writeControlWord("ds", var19);
  676.             } else {
  677.                this.writeControlWord("s", var19);
  678.             }
  679.  
  680.             AttributeSet var9 = var17.getResolveParent();
  681.             SimpleAttributeSet var10;
  682.             if (var9 == null) {
  683.                var10 = new SimpleAttributeSet();
  684.             } else {
  685.                var10 = new SimpleAttributeSet(var9);
  686.             }
  687.  
  688.             this.updateSectionAttributes(var10, var17, false);
  689.             this.updateParagraphAttributes(var10, var17, false);
  690.             this.updateCharacterAttributes(var10, var17, false);
  691.             var9 = var17.getResolveParent();
  692.             if (var9 != null && var9 instanceof Style) {
  693.                Integer var11 = (Integer)this.styleTable.get(var9);
  694.                if (var11 != null) {
  695.                   this.writeControlWord("sbasedon", var11);
  696.                }
  697.             }
  698.  
  699.             Style var22 = (Style)var17.getAttribute("style:nextStyle");
  700.             if (var22 != null) {
  701.                Integer var12 = (Integer)this.styleTable.get(var22);
  702.                if (var12 != null) {
  703.                   this.writeControlWord("snext", var12);
  704.                }
  705.             }
  706.  
  707.             Boolean var23 = (Boolean)var17.getAttribute("style:hidden");
  708.             if (var23 != null && var23) {
  709.                this.writeControlWord("shidden");
  710.             }
  711.  
  712.             Boolean var13 = (Boolean)var17.getAttribute("style:additive");
  713.             if (var13 != null && var13) {
  714.                this.writeControlWord("additive");
  715.             }
  716.  
  717.             this.writeText(var17.getName());
  718.             this.writeText(";");
  719.             this.writeEndgroup();
  720.          }
  721.  
  722.          this.writeEndgroup();
  723.          this.writeLineBreak();
  724.       }
  725.  
  726.       this.outputAttributes = new SimpleAttributeSet();
  727.    }
  728.  
  729.    public void writeRTFTrailer() throws IOException {
  730.       this.writeEndgroup();
  731.       this.writeLineBreak();
  732.    }
  733.  
  734.    public void writeRawString(String var1) throws IOException {
  735.       int var2 = var1.length();
  736.  
  737.       for(int var3 = 0; var3 < var2; ++var3) {
  738.          this.outputStream.write(var1.charAt(var3));
  739.       }
  740.  
  741.    }
  742.  
  743.    public void writeText(String var1) throws IOException {
  744.       int var2 = 0;
  745.  
  746.       for(int var3 = var1.length(); var2 < var3; ++var2) {
  747.          this.writeCharacter(var1.charAt(var2));
  748.       }
  749.  
  750.    }
  751.  
  752.    public void writeText(Segment var1) throws IOException {
  753.       int var2 = var1.offset;
  754.       int var3 = var2 + var1.count;
  755.  
  756.       for(char[] var4 = var1.array; var2 < var3; ++var2) {
  757.          this.writeCharacter(var4[var2]);
  758.       }
  759.  
  760.    }
  761.  
  762.    public void writeTextElement(Element var1) throws IOException {
  763.       this.updateCharacterAttributes(this.outputAttributes, var1.getAttributes(), true);
  764.       if (var1.isLeaf()) {
  765.          try {
  766.             var1.getDocument().getText(var1.getStartOffset(), var1.getEndOffset() - var1.getStartOffset(), this.workingSegment);
  767.          } catch (BadLocationException var4) {
  768.             ((Throwable)var4).printStackTrace();
  769.             throw new InternalError(((Throwable)var4).getMessage());
  770.          }
  771.  
  772.          this.writeText(this.workingSegment);
  773.       } else {
  774.          int var2 = var1.getElementCount();
  775.  
  776.          for(int var3 = 0; var3 < var2; ++var3) {
  777.             this.writeTextElement(var1.getElement(var3));
  778.          }
  779.       }
  780.  
  781.    }
  782. }
  783.